using System;
using System.Collections.Generic;
using System.Text;
using Spring.Context;
using Spring.Context.Support;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using PostSharp4Spring.Sample.Domain;

namespace PostSharp4Spring.Sample
{
    class Program
    {
        static void Main(string[] args)
        {
            IApplicationContext appContext = new XmlApplicationContext("file://config.xml");
            ContextRegistry.RegisterContext( appContext);

            //DomainObject obj = new DerivedDomainObject();
            //Console.WriteLine("Message = {0}", obj.DependentObject.Message);

            //DomainObject serializedDomainObject = (DomainObject)Transport(obj);
            //Console.WriteLine("Message = {0}", serializedDomainObject.DependentObject.Message);

            Console.WriteLine("#####################");

            Person gael = new Person("Gael");
            Console.WriteLine(gael);

            Person thomas = new Person("Thomas");
            Console.WriteLine(thomas);

            Person clonedThomas = (Person)Transport(thomas);
            Console.WriteLine(clonedThomas);
        }

        private static object Transport(object obj)
        {
            MemoryStream memoryStream = new MemoryStream();
            BinaryFormatter binaryFormatter = new BinaryFormatter();
            binaryFormatter.Serialize(memoryStream, obj);
            memoryStream.Position = 0;
            return binaryFormatter.Deserialize(memoryStream);
        }
    }
}
